Hi all. I have trouble with viewCache.
In config.php i have next config for cach folder.
'cacheDir' => APP_PATH . '/app/cache/',
It`s work fine for volts and metaData files.
My servises.php:
use Phalcon\Cache\Frontend\Output as OutputFrontend;
use Phalcon\Cache\Backend\File as FileBackend;
...........................
//Set the views cache service
$di->set('viewCache', function () use ($config) {
$frontCache = new OutputFrontend(
array(
"lifetime" => 86400
)
);
//Set the cache directory
$backendOptions = array(
'cacheDir' => $config->application->cacheDir . 'view/',
);
$cache = new FileBackend(
$frontCache,
$backendOptions
);
return $cache;
});
folder 'view' created and writable.
In my controller I have next action:
public function showAction($post_id, $slug)
{
$exists = $this->view->getCache()->exists($post_id.$slug);
// var_dump($exists); exit; // I`ts return false
if (!$exists) {
$post = Posts::findFirst($post_id);
if (!$post) {
$this->flash->error("The Post not exist!");
return $this->response->redirect('/post/index');
}
// +1 to view counter
$post->PostsViews->incrementByOne();
$this->assets
->collection('css-acticle-blog')
->addCss('blog/css/article.css');
$this->view->setVar('show_slider', false);
$this->view->setVar('show_post', true);
$this->view->setVar('post', $post);
$this->tag->prependTitle($post->title);
}
$this->view->cache(array("lifetime" => 86400, "key" => $post_id.$slug));
}
Files in view folder not created. What I do wrong and have make this working?